//
// Created by GYC on 2021/6/4.
//
#include "../../common.h"

class Solution {
public:
    int findMaxLength(vector<int> &nums) {

        unordered_map<int, int> note{};
        note[0] = -1;
        int last = 0, len = 0;
        for (int i = 0; i < nums.size(); ++i) {
            last += (nums[i] == 1 ? 1 : -1);
            if (note.count(last)) {
                len = max(len, i - note[last]);
            }else {
                note[last] = i;
            }
        }
        return len;
    }
};
